//
//  HLRecommendNetManager.swift
//  HLXiMaLaYa
//
//  Created by hulinhu on 2018/1/24.
//  Copyright © 2018年 hulinhu. All rights reserved.
//

import UIKit
import Moya

enum HLRecommendNetManager {
    
    enum HLNetWorkStyleType: String {
     
        case iOS      = "iOS"
        case Android  = "Android"
        case Category = "Category"
    }
    case GETRecommendList       // 下拉刷新
    case GETRecommendPullList(Int)  // 上拉加载
    case GETBoutiquePullList        // 精选请求数据
}

extension HLRecommendNetManager : TargetType {
    
    /// The headers to be used in the request.
    var headers: [String : String]? {
        return nil
    }
    /// The target's base `URL`.
    var baseURL: URL {
        return URL.init(string: "http://mobwsa.ximalaya.com/")!
    }
    
    /// The path to be appended to `baseURL` to form the full `URL`.
    var path: String {
        switch self {
        case .GETRecommendList: // 不带参数的请求
            return "discovery-firstpage/explore/ts-1513673738360"
        case .GETRecommendPullList (_):  // 带参数的请求
            return "mobile/discovery/v4/recommend/albums"
        case .GETBoutiquePullList :  // 带参数的请求
            return "mobile/discovery/v5/category/recommends/ts-1515906325392"
        }
    }
    /// The HTTP method used in the request.
    var method: Moya.Method {
        return .get
    }
    /// The method used for parameter encoding.
    var parameterEncoding: ParameterEncoding {
        return URLEncoding.default
    }
    /// Provides stub data for use in testing.
    var sampleData: Data {
        return "".data(using: String.Encoding.utf8)!
    }
    /// The type of HTTP task to be performed.
    ///  注意GET 请求 参数配置 不识别 & 链接
    var task: Task {
        let baseParameters = ["appid":"0","device":"iPhone","deviceId":"49AF49CB-60ED-4CF5-84BD-21E9E016956E","network":"WIFI","operator":"3","scale":"2","uid":"0","version":"6.3.45"]
        switch self {
            case .GETRecommendList:
                 var recommendListParms = ["categoryId":"-2","channel":"ios-b1","code":"43_440000_4403","includeActivity":"true","includeSpecial":"true","xt":"1513670067079"]
                 for e in baseParameters {
                    recommendListParms[e.key] = baseParameters[e.key]
                 }
                  return .requestParameters(parameters: recommendListParms, encoding:URLEncoding.default)
            case.GETRecommendPullList(let id):
                var recommendPullListParms = ["excludedAlbumIds":"10985438%2C4576194%2C8273989%2C338785%2C10160333%2C289147%2C5938428%2C5509952%2C10817293%2C11608277%2C11626796%2C11728511%2C10646371%2C6434420%2C3703879%2C9580491%2C10105195%2C2833949%2C353456%2C11940288%2C10846734%2C4038879%2C238474%2C10817349%2C11486581%2C6982423%2C11774689","xt":"1513673738361","pageId":"\(id)","pageSize":"20"]
                 for e in baseParameters {
                    recommendPullListParms[e.key] = baseParameters[e.key]
                }
                return .requestParameters(parameters: recommendPullListParms, encoding:URLEncoding.default)
            
            case .GETBoutiquePullList:
                var boutiquePullListParms = ["categoryId":"33","contentType":"album","xt":"1515906325392"]
                for e in baseParameters {
                    boutiquePullListParms[e.key] = baseParameters[e.key]
                }
                return .requestParameters(parameters: boutiquePullListParms, encoding:URLEncoding.default)

        }
    }
}
